package com.offices.subscribe.dto;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@Scope("singleton")
@ConfigurationProperties(prefix = "accesstoken")
public class AccessToken {
    private String url;
    private String grant_type;
    private String appid;
    private String secret;
//    存储令牌
    private String access_token;
//    过期间隔
    private String expires_in;
//    下一次过期时间
    private long expireAt;

    /**
     *@classname AccessToken
     *@description :重载lombok方法，计算过期时间
     *@param expires_in
     *@return void
     *@author :[prove]
     *@date :2020/04/28 17:08
     */
    public void setExpires_in(String expires_in) {
//        计算出下一次过期的时间
        this.expireAt = System.currentTimeMillis() + Integer.parseInt(expires_in)*1000;
    }
    /**
     *@classname  AccessToken
     *@description : 判断token是否过期
     *@return :boolean
     *@author :作者
     *@date :2020/04/28 17:06
     */
    public boolean isExpires() {
//        当前时间大于过期时间表示过期true
        return System.currentTimeMillis() > this.expireAt;
    }

}
